package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.AreaBean;
import com.project.bean.ClassBean;
import com.project.service.IClassService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author RJ
 * @date 2022/9/16 10:01
 */
@RestController
@RequestMapping("class")
public class ClassController {
    @Resource
    private IClassService classService;

    @RequestMapping("add")
    public String addClass(ClassBean classBean, Integer areaId) {
        AreaBean areaBean = new AreaBean();
        areaBean.setAreaId(areaId);
        classBean.setTheArea(areaBean);
        //System.out.println(classBean);
        classService.addClass(classBean);
        return "ok";
    }

    @RequestMapping("get")
    public ClassBean getClassInfo(Integer classId) {
        ClassBean classBean = classService.getClassInfo(classId);
        return classBean;
    }

    @RequestMapping("update")
    public String updClass(Integer classId, String classManager, String classPhone) {
        classService.updClass(classId, classManager, classPhone);
        return "ok";
    }

    @RequestMapping("info")
    public IPage<ClassBean> cutClassByItem(Integer pageNo, Integer pageSize, String className, String areaName) {
        IPage<ClassBean> page = classService.cutClassByItem(pageNo, pageSize, className, areaName);
        return page;
    }
}
